package Core.Map;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CombatGridGraph
{
	private List<TileVertex> _vertices;
	private List<TileEdge> _edges;
	
	public CombatGridGraph()
	{
		this._vertices = new ArrayList<TileVertex>();
		this._edges = new ArrayList<TileEdge>();
	}
	
	public void addVertex(TileVertex newVertex)
	{
		this._vertices.add(newVertex);
	}
	
	public TileVertex[] getVertices()
	{
		return this._vertices.toArray(new TileVertex[0]);
	}

	public void addEdge(int firstX, int firstY, int secondX, int secondY, double cost)
	{
		TileVertex firstVertex = this.findVertex(firstX, firstY);
		TileVertex secondVertex = this.findVertex(secondX, secondY);
		
		this._edges.add(new TileEdge(firstVertex, secondVertex, cost));
	}
	
	private TileVertex findVertex(int x, int y)
	{
		Iterator<TileVertex> vertexIterator = this._vertices.iterator();
		TileVertex foundVertex = null;
		
		while (vertexIterator.hasNext() && foundVertex == null)
		{
			TileVertex currentVertex = vertexIterator.next();
			
			if (currentVertex.getX() == x && currentVertex.getY() == y)
			{
				foundVertex = currentVertex;
			}
		}
		
		return foundVertex;
	}
}
